package com.shengwei.truck.driver.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import com.shengwei.truck.driver.socket.SocketService;
import com.shengwei.truck.driver.utils.MyLogFile;

/**
 * Service服务随操作系统启动而启动
 */
public class BootReceiver extends BroadcastReceiver {
    private static final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";
    @Override
    public void onReceive(Context context, Intent intent) {
        String action=intent.getAction();
       if(action.equals(ACTION_BOOT)) {
           if (Build.VERSION.SDK_INT >= 26) {
               MyLogFile.i("BootReceiver", "自启动 >= 26");
               context.startForegroundService(new Intent(context, SocketService.class));
           } else {
               MyLogFile.i("BootReceiver", "自启动 < 26");
               context.startService(new Intent(context, SocketService.class));
           }
       }
    }
}
